package com.ruoyi.orderview.service.impl;

import com.ruoyi.orderview.domain.ProductionParam;
import com.ruoyi.orderview.mapper.ChartsMapper;
import com.ruoyi.orderview.service.ChartsService;

import com.ruoyi.orderview.utils.ProductionDistinguish;
import com.ruoyi.orderview.utils.StorageSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Author 许家森
 * Date 2022/2/22
 * Email 3448324670@qq.com
 */
@Service
public class ChartsServiceImpl implements ChartsService {
    @Autowired
    private ChartsMapper chartsMapper;

    @Autowired
    private StorageSelect storageSelect;

    @Override
    public List<List<Map<Object, Object>>> selectPurchase(ProductionParam productionParam) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        String origintime = f.format(productionParam.getOrigintime());
        String endtime = f.format(productionParam.getEndtime());

        ArrayList productioncharts = new ArrayList();

        System.out.println(productionParam.getProductiontype());

        ProductionDistinguish productionDistinguish = new ProductionDistinguish(productionParam);


        productioncharts.add(chartsMapper.selectPurchase(origintime,endtime,productionDistinguish.getPurchase()));
        productioncharts.add(chartsMapper.selectConsume(origintime,endtime,productionDistinguish.getConsume()));
        //stroma的consume_tempoay与其他表不同
        if(productionParam.getProductiontype().equals("stroma")){
            productioncharts.add(chartsMapper.selectStromaConsumeTemporary(origintime,endtime));
        }else {
            productioncharts.add(chartsMapper.selectConsumeTemporary(origintime, endtime, productionDistinguish.getConsumetemporary()));
        }
        productioncharts.add(chartsMapper.selectReturn(origintime,endtime,productionDistinguish.getReturna()));

        productioncharts.add(storageSelect.StoragesSelect());

        productioncharts.add(chartsMapper.selectPurcahseTotal(origintime,endtime,productionDistinguish.getPurchase()));
        return productioncharts;
    }
}
